<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.title.center_zhuyonghu"></spring:message></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
       
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>儿童健康手册</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
             <li class="active"><a href="#">儿童健康手册</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            
            
            
            
            
                <form id="form">
                    <div class="input">
                    <div class="textalign1">标题：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="title" name="title" placeholder="标题" maxlength="25" />
                    </div>
                    <div class="textalign1">手册类型：</div>
                    <div class="boxinput">
                    <select class="textinput" id="mtype" name="mtype">
                    	<option value="">请选择</option>
                    	<option value="1">健康知识</option>
                    	<option value="2">疾病预防</option>
                    	<option value="3">育苗接种</option>
                    </select>
                    </div>
                    <div class="textalign1"> 年龄段：</div>
                    <div class="boxinput">
                    <table style="width:100%;">
                           <tr>
                              <td style="width:33%">
                               <input class="textinput" type="text" id="satart_age"  name="satart_age" />
                              </td>
                              <td style="width:5%" align="center">-</td>
                              <td style="width:33%">
                               <input class="textinput" type="text" id="end_age"  name="end_age" />
                                </td>
                           </tr>
                        </table>
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查 询</button>
                </div>
               
              </form>  
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<label id="addNew" onclick="javascript:window.location.href='${ctx}/childManual/toAdd.html'" class="btn btn-default btn-sm">新 增</label>
			<label id="addNew" onclick="deleteUser();" class="btn btn-default btn-sm">删 除</label>
		</div>
		
		
		
		
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">

    function deleteUser(){
		 var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
		 if (rowIds.length < 1){
			 $.HN.message.alert("请选择要删除的手册！", "warn");
			 return;
		 }
	    	var list = [];
	    	for(var i = 0;i<rowIds.length;i++){
				list.push({"id":rowIds[i]});
			}
	    	$.HN.message.confirm("确定要删除所选手册？", '', '').on(function (e) {
	            if (e) {
			$.post("${pageContext.request.contextPath}/childManual/deleteUser.html", {
				"array" : json.jsonToString(list)
			}, function(result) {
				if (result.success) {
					$.HN.message.alert("删除成功！", "success");
					$("#gridlist").trigger("reloadGrid");
				} else {
					$.HN.message.alert("删除失败！", "error");
				}
			}, "json");
	            }
			});
	 }
    function editInfo(){
    	
   	if ($("#edittitle").val().length < 1){
			 $.HN.message.alert("标题不能为空！", "warn");
			 return;
		 }
   	if ($("#editcontent").val().length < 1){
			 $.HN.message.alert("内容不能为空！", "warn");
			 return;
		 }
    	$.HN.message.confirm("确定要保存？", '', '').on(function (e) {
            if (e) {
         		$("#editForm").ajaxSubmit({
      			dataType : "json",
      			timeout: 10000,
      			success : function(result, statusText) {
      				if (result.success) {
      					    $('#userEdit').modal('hide');
      					    search( $("#gridlist").getGridParam("page"));
      					    top.$.HN.message.alert("修改成功！", "<spring:message code='message.HN.alert.type'/>", "success");
      				} else {
      					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
      				}
      			}
      		});
  		}
     	  });
    }
    function showEdit(id){
    	window.location.href="${pageContext.request.contextPath}/childManual/toEdit.html?id="+id;
    	
    }
    function addUser(){
    	alert(editor.getContent());
    	return;
    	if ($("#addtitle").val().length < 1){
			 $.HN.message.alert("标题不能为空！", "warn");
			 return;
		 }
    	if ($("#addcontent").val().length < 1){
			 $.HN.message.alert("内容不能为空！", "warn");
			 return;
		 }
    	$.HN.message.confirm("确定要保存？", '', '').on(function (e) {
            if (e) {
         		$("#addForm").ajaxSubmit({
      			dataType : "json",
      			timeout: 10000,
      			success : function(result, statusText) {
      				if (result.success) {
      					    $('#userAdd').modal('hide');
      					    search( $("#gridlist").getGridParam("page"));
      					    top.$.HN.message.alert("<spring:message code='message.HN.alert.success'/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code='message.HN.alert.type'/>", "success");
      				} else {
      					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
      				}
      			}
      		});
  		}
     	  });
    }
		 function showAddPage(){
			 $('#addForm')[0].reset();
			 $('#userAdd').modal({
	                keyboard: true
	            });
		 }
    	function search(page) {
    		var data = formatForm("form");
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:data,
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/childManual/getChildManualList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 250,
                colNames: ['操作', '标题','手册类型', '适用年龄段', '创建时间'],
                colModel: [
					{ name: 'id', width: 8, align:"left", sortable: false,formatter : function(val, opts, rowdata) {
				            var str = "<a href='#' onclick='showEdit(\""+val+"\")'>修改</a>";
	    	                return str;
	                    }},
                    { name: 'title', width: 10, align:"left", sortable: false},
                    { name: 'mtype', width: 5, align:"center", sortable: false },
                    { name: 'end_age', width: 5, align:"center", sortable: false ,formatter : function(val, opts, rowdata) {
    	                return rowdata.satart_age +"—" + val;
                    }},
                    { name: 'create_time', width: 10, align: 'left', sortable: false}
                ],
                rowNum: 20,
                rowList: [10, 20, 30],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "儿童健康手册列表",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                },
                jsonReader: {
                    id: "id"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
    </script>
</body>
</html>












